package com.my.socket;

import java.io.*;
import java.net.Socket;

/**
 * @author: marshal
 * @date: 2021-12-30 2:45 PM
 */
public class MyClient {
    public static void main(String[] args) {
        try (Socket s = new Socket("127.0.0.1", 8888)) {
            //构建IO
            InputStream is = s.getInputStream();
            OutputStream os = s.getOutputStream();

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            //向服务器端发送一条消息
            bw.write("來自客戶端的消息\n");
            bw.flush();

            //读取服务器返回的消息
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String mess = br.readLine();
            System.out.println("服务器：" + mess);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
